$(function() {
	$(':input').labelauty();
	setMyActive(4,1,1); //设置激活页
});

// 号码变动时的操作 修改样式
function changemobileExt1(obj) {
	$("#disprice").empty();
	$("#billpkgids").empty();
	var searchStatus = '查询中请稍后';
	var mobilenumber = $("#mobilenumber").val();
	platform_verify.onblurVali(obj);
	var length = mobilenumber.length;
	$("#disprice").val("");

	var isNumV1Flag = isNumberV1(mobilenumber);
	if (!isNumV1Flag) {
		$("#phoneMessage").html('手机号格式不正确');
	}

	if (length == 11 || length == 13 && isNumV1Flag) {
		$("#phoneMessage").html(searchStatus);
		$.ajax({
			type : "get",
			url : basePath + 'sectionAndBillPkgGet',
			data : {
				"phone" : mobilenumber,
			},
			dataType : "json",
			success : function(dt) {
				if (dt != "" && dt != null) {
					$("#phoneMessage").html(dt.province_code + "-" + dt.city_code+"-"+dt.providerName);
					$("#terminalName").val(dt.agentName);
					var billpkgids = $("#billpkgids");
					$("#billpkgids").empty();
					$.each(dt.billPkgMessage, function(index,val) {
					     var li="<li>"+"<input type='radio' " +
					     		"name='billpkgs' onclick='changeBillPkgExt(this);' pkgId="+val.id+"  providerId="+val.provider_id+"" +
					     				" value="+val.price+" data-labelauty='"+val.value+"元'/>"+"</li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
					     billpkgids.append(li);
					    });	
				} else {
					$("#phoneMessage").html('未知');
				}
				$('input[name=billpkgs]').labelauty();
			},
			error:function(dt){
				swal({
 			        title: "系统异常",
 			        type: "success",
 			        confirmButtonText: "ok"
 				});
			}
		});
	}
	if (length == 0) {
		$("#disprice").val('');
		$("#terminalName").val('');
		$("#phoneMessage").html('');
	}
}

function changeBillPkgExt(obj) {
	$("#disprice").val('');
	var pkgId= $(obj).attr("pkgId");
	var providerId=$(obj).attr("providerId");
	$.ajax({
		type : "get",
		url : basePath + 'agentBillDiscountGet',
		data : {
			"billPkgId" : pkgId,
			"providerId" : providerId,
		},
		success:function(dt){			
			if (dt != "0") {
				$("#disprice").val(dt);
			}else{
				$("#disprice").val('未查询到折扣');
			}
			
		},	
		dataType : "json"
	});
		
}

function isNumberV1(str) {
	var myNumber = /^[0-9]+$/;
	return myNumber.test(str);
}

function submitOrder() {
	var terminalName = $("#terminalName").val();
	var phoneNo = $("#mobilenumber").val();
	var timestamp = getTimestamp();
	var spec = $("input[name='billpkgs']:checked").val();
	var orderType = "2";
	var scope = "nation";
	var callbackUrl = "baidu.com";
	var signature = "6666666";
	$.ajax({
		type : "get",
		url : basePath + 'order/quotaOrder',
		data : {
			"terminalName" : terminalName,
			"phoneNo" : phoneNo,
			"customerOrderId" : timestamp+phoneNo,
			"timeStamp" : timestamp,
			"callbackUrl" : callbackUrl,
			"signature" : signature,
			"spec" : parseInt(spec) * 100,
			"orderType" : orderType,
			"scope" : scope
		},
		success : function(dt) {
			alert(dt.message);
		},
		dataType : 'json'
	});
}

function getTimestamp() {
	var now = new Date();

	var year = now.getFullYear(); // 年
	var month = now.getMonth() + 1; // 月
	var day = now.getDate(); // 日

	var hh = now.getHours(); // 时
	var mm = now.getMinutes(); // 分
	var ss = now.getSeconds(); // 秒
	var sss = now.getMilliseconds();//毫秒
	var timeStamp = year + "";
	if (month < 10) {
		timeStamp += "0";
		timeStamp += month + "";
	} else {
		timeStamp += month + "";
	}
	if (day < 10) {
		timeStamp += "0";
		timeStamp += day + "";
	} else {
		timeStamp += day + "";
	}
	if (hh < 10) {
		timeStamp += "0";
		timeStamp += hh + "";
	} else {
		timeStamp += hh + "";
	}
	if (mm < 10) {
		timeStamp += "0";
		timeStamp += mm + "";
	} else {
		timeStamp += mm + "";
	}
	if (ss < 10) {
		timeStamp += "0";
		timeStamp += ss + "";
	} else {
		timeStamp += ss + "";
	}
	if (sss < 10) {
		timeStamp += "00";
		timeStamp += sss + "";
	} else if (sss < 100) {
		timeStamp += "0";
		timeStamp += sss + "";
	} else {
		timeStamp += sss + "";
	}

	return timeStamp;
}